package com.github.itdachen.product.service.impl;

import com.github.itdachen.framework.core.response.TableData;
import com.github.itdachen.framework.webmvc.service.impl.BizServiceImpl;
import com.github.itdachen.framework.webmvc.poi.WorkBookUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.itdachen.product.entity.ProductClazzInfo;
import com.github.itdachen.product.sdk.dto.ProductClazzInfoDTO;
import com.github.itdachen.product.sdk.query.ProductClazzInfoQuery;
import com.github.itdachen.product.sdk.vo.ProductClazzInfoVO;
import com.github.itdachen.product.mapper.IProductClazzInfoMapper;
import com.github.itdachen.product.service.IProductClazzInfoService;
import com.github.itdachen.product.convert.ProductClazzInfoConvert;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * 产品类目 业务实现
 *
 * @author 王大宸
 * @date 2025-03-04 15:48:47
 */
@Service
public class ProductClazzInfoServiceImpl extends BizServiceImpl<IProductClazzInfoMapper, ProductClazzInfo, ProductClazzInfoDTO, ProductClazzInfoVO, ProductClazzInfoQuery, String> implements IProductClazzInfoService {
    private static final Logger logger = LoggerFactory.getLogger(ProductClazzInfoServiceImpl.class);
    private static final ProductClazzInfoConvert bizConvert = new ProductClazzInfoConvert();
    private final List<String> EXP_FIELDS = new ArrayList<>();

    public ProductClazzInfoServiceImpl() {
        EXP_FIELDS.add("应用ID, 备用字段");
        EXP_FIELDS.add("第一层ID");
        EXP_FIELDS.add("上级ID");
        EXP_FIELDS.add("分类层级, 最多三级");
        EXP_FIELDS.add("标题名称");
        EXP_FIELDS.add("图标");
        EXP_FIELDS.add("排序");
        EXP_FIELDS.add("是否展示/有效标志: Y-有效;N-无效");
        EXP_FIELDS.add("删除标志: Y-已删除;N-未删除");
    }

    /***
     * 分页
     *
     * @author 王大宸
     * @date 2025-03-04 15:48:47
     * @param params params
     * @return com.github.itdachen.framework.core.response.TableData<com.github.itdachen.product.sdk.vo.productClazzInfoVo>
     */
    @Override
    public TableData<ProductClazzInfoVO> page(ProductClazzInfoQuery params) throws Exception {
        Page<ProductClazzInfoVO> page = PageHelper.startPage(params.getPage(), params.getLimit());
        List<ProductClazzInfoVO> list = bizMapper.list(params);
        return new TableData<ProductClazzInfoVO>(page.getTotal(), list);
    }


    /***
     * 导出
     *
     * @author 王大宸
     * @date 2025-03-04 15:48:47
     * @param params com.github.itdachen.product.sdk.query.ProductClazzInfoQuery
     * @return void
     */
    @Override
    public void expInfo(HttpServletRequest request,
                        HttpServletResponse response,
                        ProductClazzInfoQuery params) throws Exception {
        List<LinkedHashMap<String, String>> list = bizMapper.selectProductClazzInfoExpData(params);
        WorkBookUtils.export(request, response)
                .params(params)
                .title("产品类目")
                .rowNum(true)
                .fields(EXP_FIELDS)
                .data(list)
                .execute();
    }

}
